<?php
include '../dbconnect.php';
?>

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <!-- <meta name="description" content=""> -->
    <!-- <meta name="author" content=""> -->
    <!-- <link rel="icon" href="../../favicon.ico"> -->

    <title>编辑员工</title>

    <!-- Bootstrap core CSS -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> -->

    <!-- Custom styles for this template -->
    <link href="./css/navbar-fixed-top.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don t actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <!-- <script src="../assets/js/ie-emulation-modes-warning.js"></script> -->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<!-- Fixed navbar -->
<?php include 'adminHeader.php'; ?>

<div class="container">
    <br><br><br><br><br>
    <table class="table">
        <thead>
            <tr>
                <th colspan="2">编辑员工</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $uid = isset($_GET['uid']) ? $_GET['uid'] : '';
            if (empty($uid)) {
                echo "员工ID不能为空！";
                exit;
            }

            // 使用预处理语句查询员工信息
            $sql = "SELECT * FROM staff WHERE S_ID = ?";
            $stmt = $conn->prepare($sql);
            $stmt->bind_param("s", $uid);
            $stmt->execute();
            $result = $stmt->get_result();

            if ($result->num_rows > 0) {
                while ($row = $result->fetch_assoc()) {
                    ?>
                    <form class="" action="doeditEmployee.php?uid=<?php echo $row['S_ID']; ?>" method="post">
                        <tr>
                            <td>用户名：</td>
                            <td>
                                <input type="text" name="username" value="<?php echo htmlspecialchars($row['S_Username']); ?>">
                            </td>
                        </tr>

                        <tr>
                            <td>密码：</td>
                            <td>
                                <input type="text" name="password" value="<?php echo htmlspecialchars($row['S_Password']); ?>">
                            </td>
                        </tr>

                        <tr>
                            <td>邮箱：</td>
                            <td>
                                <input type="text" name="email" value="<?php echo htmlspecialchars($row['S_Email']); ?>">
                            </td>
                        </tr>

                        <tr>
                            <td colspan="2">
                                <input type="submit" class="btn btn-success" value="更新">
                            </td>
                        </tr>
                    </form>
                    <?php
                }
            } else {
                echo "员工不存在！";
            }

            $stmt->close();
            ?>
        </tbody>
    </table>
</div> <!-- /container -->

<script src="./js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<!-- <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> -->
</body>
</html>